package scream.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import scream.dao.BastanteoDAO;
import scream.dao.RepresentanteDAO;
import scream.excepcion.DAOExcepcion;
import scream.modelo.Cliente;
import scream.modelo.Poder;
import scream.modelo.Representante;

/**
 * Servlet implementation class CargaVerificarPoder
 */
@WebServlet("/CargaVerificarPoder")
public class CargaVerificarPoder extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CargaVerificarPoder() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		BastanteoDAO ba = new BastanteoDAO();
		RepresentanteDAO rdao = new RepresentanteDAO();
		Collection<Cliente> c = new ArrayList<Cliente>();
		Collection<Representante> r = new ArrayList<Representante>();
		Collection<Poder> p = new ArrayList<Poder>();

		try {
			c = ba.listar_clientes();
			r = rdao.Buscar_Repre_x_Cliente("");
			p = ba.Listar_Poderes();

			request.setAttribute("clientes", c);
			request.setAttribute("representantes", r);
			request.setAttribute("poderes", p);
			System.out.println("RESPUESTA 2 ==> "
					+ request.getAttribute("rest") + " <====");

			request.setAttribute("mirespuesta", request.getAttribute("rest"));

			RequestDispatcher rd = request
					.getRequestDispatcher("VerificarPoder.jsp");
			rd.forward(request, response);

		} catch (DAOExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
